<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var user = {
            'name': '张三',
            'age': '20',
            'sex': '男'
        }

        // 把JSON对象转换为字符串
        var userStr = JSON.stringify(user);


        console.log(userStr);
        console.log('user',user,typeof user);
        console.log('userStr',userStr,typeof userStr);

        // 字符串转换为对象类型
        // JSON串属性名必须用    双引号    包裹
        // var userStr2 = "{'name': '李磊', 'age': '120', 'sex': '男'}";
        var userStr2 = '{"name": "李磊", "age": "52", "sex": "男"}'
        var user2 = JSON.parse(userStr2);
        console.log('user2',user2,typeof user2);
        console.log('userStr2', userStr2, typeof userStr2);
    </script>
</body>
</html>